;**********************************************
; Macroses for global variables handling.
; This macro library is part of Fresh project.
;
; (C)2003, 2004
;
; Authors:
;   John Found
;   Tomasz Grisztar
;
; usage:
;   1. Include this library in the begining
;      of your source file.
;   2. Use it as blocks anywhere in the source.
;        iglobal
;           somelabel dd 1234h
;           otherlabel RECT
;           lbl3       db 12h
;        endg
;
;   3. Data section must be at the end of the
;      source file. Use 'IncludeAllGlobals' to
;      really define variables.
;
;**********************************************

macro iglobal { IGlobals equ IGlobals,
		macro __IGlobalBlock { }

macro uglobal { UGlobals equ UGlobals,
		macro __UGlobalBlock { }

endg fix }

macro IncludeIGlobals { macro IGlobals dummy,[n] \{ __IGlobalBlock
						    purge __IGlobalBlock \}
			match I, IGlobals \{ I \} }


macro IncludeUGlobals { macro UGlobals dummy,[n] \{ \common \local begin, size
						     begin = $
						     virtual at $
						    \forward
						     __UGlobalBlock
						     purge __UGlobalBlock
						    \common
						     size = $ - begin
						     end virtual
						     rb size \}
			match U, UGlobals \{ U \} }


;--------------------------------------------
; constStr Str1, 'This is string constant'
;--------------------------------------------
macro constStr	lbl, text {
  __StringsArray equ __StringsArray, lbl, text	   ;  add to the list
}


macro __IncludeStringConstants dummy,[lbls, text] {
  forward
    if text eqtype 'A'
      lbls db text
      sizeof.#lbls = $ - lbls
      db 0
    else
      if text eqtype 0
	lbls = text
      end if
    end if
}

macro IncludeStringConstants {
 match strings, __StringsArray \{ __IncludeStringConstants strings \}

}


__StringsArray equ

macro IncludeAllGlobals {
  local begin

  begin = $
  IncludeIGlobals
  DispSize 'Initialized data', ($ - begin)

  begin = $
  IncludeStringConstants
  DispSize 'String constants data', ($ - begin)

  begin = $
  IncludeUGlobals
  DispSize 'Uninitialized data', ($ - begin)
}

iglobal
endg

uglobal
endg